package com.yunfei.api.v2.service;
import com.yunfei.api.v2.elecHeTong.json.ContractTable;
import com.yunfei.api.v2.elecHeTong.json.ContractTables;
import com.yunfei.api.v2.param.ReserveNoParam;
import com.yunfei.api.v2.result.TableResult;
import com.yunfei.api.v2.result.YuYueInfoResult;
import com.yunfei.bo.result.ResultModel;
import com.yunfei.enums.HeTongSignInfoGetStatusResultStatus;
import com.yunfei.enums.ResultStatus;
import com.yunfei.mapper.aiiidb.YuYueInfoMapper;
import com.yunfei.utils.string.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class HTYuYueInfoService {
    @Autowired
    private YuYueInfoMapper yuYueInfoMapper;
    public ResultModel get(ReserveNoParam param){
        ResultModel resultModel=new ResultModel();
        Map<String,Object> queryMap=new HashMap<>();
        try{
            String reserveNo=param.getReserveNo();//预约编号
            if(StringUtil.isNullOrEmpty(reserveNo)){
                resultModel.setCode(HeTongSignInfoGetStatusResultStatus.RESERVENO_NOTNULL.getCode());
                resultModel.setMessage(HeTongSignInfoGetStatusResultStatus.RESERVENO_NOTNULL.getMessage());
                return resultModel;
            }
            queryMap.put("reserveNo",reserveNo);
            YuYueInfoResult yuYueInfoResult=yuYueInfoMapper.get(queryMap);
           //解决无法换行的问题，Word换行主要有两大类，一类是表格单元格文本的换行，另一类是表格之外的文本的换行。对于表格外的文本我们可以使用“\r”或者“(char)11”来换行，然而对于表格内的文本我们只能使用“(char)11”来进行换行操作。
            //需要换行的元素
            if(!StringUtil.isNullOrEmpty(yuYueInfoResult)){
                String undsUse=yuYueInfoResult.getUndsUse();//资金用途
                String riskControl=yuYueInfoResult.getRiskControl();//风险措施
                String repaySource=yuYueInfoResult.getRepaySource();//还款来源
                String filing=yuYueInfoResult.getFiling();//备案文件
                String huanHang="\r<br>";
                if(!StringUtil.isNullOrEmpty(undsUse)){
                    yuYueInfoResult.setUndsUse(undsUse.replace("\n",huanHang));
                }
                if(!StringUtil.isNullOrEmpty(riskControl)){
                    yuYueInfoResult.setRiskControl(riskControl.replace("\n",huanHang));
                }
                if(!StringUtil.isNullOrEmpty(repaySource)){
                    yuYueInfoResult.setRepaySource(repaySource.replace("\n",huanHang));
                }
                if(!StringUtil.isNullOrEmpty(filing)){
                    yuYueInfoResult.setFiling(filing.replace("\n",huanHang));
                }
            }
            resultModel.setData(yuYueInfoResult);
            resultModel.setCode(ResultStatus.SUCCESS.getCode());
            resultModel.setMessage(ResultStatus.SUCCESS.getMessage());
        }catch (Exception e){
            resultModel.setCode(ResultStatus.ERROR.getCode());
            resultModel.setMessage(ResultStatus.ERROR.getMessage());
            e.printStackTrace();
        }
        return resultModel;
    }

    public List<ContractTable> getTableList(Map<String, Object> projIdMap) {
        List<ContractTable> list= yuYueInfoMapper.getTableList(projIdMap);
        return list;

    }
}
